package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.bean.PledgeRecordsBean;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

import static com.lianzhihui.romeex.net.APIConstant.EXTRACT_RECORD;

/**
 * Description: 提取纪录业务
 * Author: RAMON
 * CreateDate: 11/30/20 6:10 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class ExtractRecordModelImp {

    Context context;
    ExtractRecordInterface callback;

    public ExtractRecordModelImp(Context context, ExtractRecordInterface callback) {
        this.context = context;
        this.callback = callback;
    }

    public void getExtractRecord(int pageNum,String status) {
        HttpParams params = new HttpParams();
        params.put("page", pageNum + "");
        params.put("status", status);
        params.put("pageSize", "20");

        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                PledgeRecordsBean bean = GsonUtil.GsonToBean(o.getData(), PledgeRecordsBean.class);
                if (bean != null && bean.getContent() != null) {
                    callback.onExtractRecordSuccess(bean.getContent());
                } else {
                    callback.onExtractRecordFail("无数据");
                }
            }

            @Override
            public void onError(ApiException e) {
                callback.onExtractRecordFail(e.getMessage());
            }
        }).post(EXTRACT_RECORD, params);

    }

}
